<template>
    <div class="bepaid">
        <!-- 订单信息 -->
        <div class="order-box" v-if="lang=='zh' ">
            <h6  v-if="data.buyer_state ==2" >对方已发货</h6>
           <h6 v-else>双方都已支付保证金</h6>
          
           <p>订单编号：{{data.exchange_code}}</p>
           <p>订单时间：{{data.submit_time}}</p>
        </div>
        <div class="order-box" v-else>
           <h6>The other party has shipped</h6>
           <p>Order number：{{data.exchange_code}}</p>
           <p>Order time：{{data.submit_time}}</p>
        </div>
        <!-- 确认信息 -->
        <div class="info-box">
            <img src="http://img.xianyufanshen.net//order/images/zhihuanxinxi@2x.png" alt="">
            <div class="goods-box"  v-for="(item,index) in inGoods" :key="index" @click="goDetails(inGoods[index].goods_id,0)">
                <div class="img-box" >
                    <img :src="item.head_img" alt="">
                    <img v-if="lang=='zh' " class="label" src="http://img.xianyufanshen.net//goods/image/huanjin@2x.png" alt="">
                    <img v-else class="label" src="http://img.xianyufanshen.net//image/jpg/enghuanjin_eng@2x.png" alt="">
                </div>
                <dl>
                    <dt style="display:-webkit-box; overflow:hidden;-webkit-box-orient: vertical; -webkit-line-clamp: 3;text-overflow: ellipsis;">{{item.title}}</dt>
                    <dd>￥{{item.goods_price}} <span>x{{item.goods_num}}</span></dd>
                </dl>
            </div>
            <div class="handle-box">
                <!-- 选择商品之后 -->
                <div class="selected">
                    <img  src="http://img.xianyufanshen.net//goods/image/zhihuan@2x.png" alt="">
                </div>
            </div>
            <!-- 自己换出的商品 -->
            <div class="sales-box">
                <div class="goods-box sold-box" @click="goDetails(outGoods.goods_id,1)">
                    <div class="img-box">
                        <img :src="outGoods.head_img" alt="">
                        <img v-if="lang=='zh' " class="label" src="http://img.xianyufanshen.net//goods/image/huanchu@2x.png" alt="">
                        <img v-else class="label" src="http://img.xianyufanshen.net//image/jpg/enghuanchu_eng@2x.png" alt="">
                    </div>
                    <dl>
                        <dt  style="display:-webkit-box; overflow:hidden;-webkit-box-orient: vertical; -webkit-line-clamp: 3;text-overflow: ellipsis;">{{outGoods.title}}</dt>
                        <dd>￥{{outGoods.goods_price}} <span>x{{outGoods.goods_num}}</span></dd>
                    </dl>
                 </div>
            </div>
           
        </div>
        <!-- 优惠买单按钮 -->
        <div class="btn-box" v-if="lang=='zh' ">
             <div class="btn" @click="submit">我要发货</div>
             <div class="close" @click="close">申请关闭交易</div>
        </div>
        <div class="btn-box" v-else>
             <div class="btn" @click="submit">I want to ship</div>
             <div class="close" @click="close">Apply to close the transaction</div>
        </div>
      
        <!-- loading -->
        <div class="loading-box" v-show="loading">
             <van-loading type="spinner" color="white" />
        </div>
    </div>
</template>
<script>
import {getOrdersDetails,postCloseOrder,postSendExpress,postRefuse,} from '@/api/order/exchange'
import { Loading,Toast,Cell, CellGroup ,RadioGroup, Radio,} from 'vant';

export default {
    name:'exchangeSend',
    //声明组件
    components:{
        [Loading.name]:Loading,
        [Radio.name]:Radio,
        [RadioGroup.name]:RadioGroup,
        [Cell.name]:Cell,
        [CellGroup.name]:CellGroup,
        [Toast.name]:Toast,
     
    },
    data (){
        return{
           lang:'zh',//当前网页语言类型 zh 中文  en 英语  
           id:0,//当前订单id
           type:1,//选择商品类型 1购买 2 置换
           userId:0,//用户id 
           data:{},//详情数据 
           outGoods:{},//换出的商品
           inGoods:[],//换进的商品 可能是多个
           radio:'3',//支付方式:1余额，2支付宝，3微信
           balance:0,//我的余额
           myBalance:'我的余额',//我的余额描述
           totalPrice:'',//购买的总价格
           loading:false,//加载提示框 是否显示(页面初始加载显示)
           isSelected:false,//是否选择了置换的商品
        
        }
    },
    //实例创建完成后被立即调用
    created (){
        //获得语言类型lang
        if(this.$route.query.lang) {
            this.lang = this.$route.query.lang;
        }
        //获取订单id
        if(this.$route.query.id && this.$route.query.id > 0){
            this.id = this.$route.query.id;
             //请求数据
             this.getAllData();
        }else{
            Toast('获得订单ID失败，请返回列表页重试'); 
            this.loading = false;
        }
        //获取用户id
        if(this.$route.query.userId && this.$route.query.userId > 0){
            this.userId = this.$route.query.userId;
             //把用户id存储在缓存
             window.localStorage.setItem("userId",this.userId);
        }else{
            this.userId = window.localStorage.getItem("userId");
        }
         //获取type
        this.type = this.$route.query.type;//根据type判断是购买还是置换
        //购买数量
        this.purchaseNum = this.$route.query.purchaseNum;
        //是否选择了换购
        if(this.$route.query.isSelected){
             this.isSelected = this.$route.query.isSelected;
        }
       
    },
    //
    methods:{
        //获得所有详情数据
        getAllData(){
            getOrdersDetails(this.id,this.lang).then(res => {
            console.log(res);
            if(res.code == 200){
                this.data = res.data;
                this.outGoods = this.data.outputGoods;
                this.inGoods = this.data.incomeGoods;
                this.totalPrice = this.data.seller_bond;
            }else {
                Toast('获取团购详情失败，请稍后再试~');
            }
            }); 
        },
       //跳转到我要发货页面
        submit(){
         
            let para = {};
           
            if(this.lang == 'zh'){
                para.title = "我要发货";
            }else{
                para.title = "I want to ship";
            }
            para.url = "/mySend?type=0&id="+this.id+"&lang="+this.lang+"&userId="+this.userId;
            // console.log(para);
            this.interaction.hLink(para);
        },
        //申请关闭交易
        close(){
           
            //跳转到关闭页面
            let para = {};
            if(this.lang == 'zh'){
                para.title = "申请关闭交易";
            }else{
                para.title = "Apply to close the transaction";
            }
            para.url = "/fackOf?id="+this.id+"&lang="+this.lang+"&userId="+this.userId;
            this.interaction.hLink(para);
        },
        //跳转到商品详情
        goDetails(id,tab){
            if(tab == 1){
                //自己的藏品
                let para = {};
                para.id = id;//藏品详情详情id (返回首页 此参数没有)
                para.linkType = "goodsDetail";
                para.lang = this.lang;//显示网页语言类型 zh中文 en英文
                if(this.lang == 'zh'){
                    para.rightBtn = "发布藏品"; //标题栏右上角按钮文字 没有该参数代表右上角没有东西
                }else{
                    para.rightBtn = "publish"; //标题栏右上角按钮文字 没有该参数代表右上角没有东西
                }
                para.HideFootBar = true; //隐藏底部操作按钮 没有该参数代表不隐藏
                this.interaction.hLinkToApp(para);
            }else{
                //不隐藏按钮
                let para = {};
                para.id = id;//藏品详情详情id (返回首页 此参数没有)
                para.linkType = "goodsDetail";
                para.lang = this.lang;//显示网页语言类型 zh中文 en英文
                if(this.lang == 'zh'){
                    para.rightBtn = "发布藏品"; //标题栏右上角按钮文字 没有该参数代表右上角没有东西
                }else{
                    para.rightBtn = "publish"; //标题栏右上角按钮文字 没有该参数代表右上角没有东西
                }
                this.interaction.hLinkToApp(para);
            }
            	
        },

    }
    
}
</script>

<style lang="stylus" scoped>
.bepaid{
    height:100%;
}
// 订单顶部信息
.order-box{
   padding :.4rem .266667rem; 
   height:2.666667rem;
   background :url("http://img.xianyufanshen.net//order/images/beijing_dingdanxiangqing@2x.png") no-repeat;
   background-size:100%;
   box-sizing :border-box;
   h6{
       font-family:PingFangSC-Medium;
        font-size:.4rem;
        color:#cb9c57;
        letter-spacing:.0112rem;
        text-align:left;
        line-height :.533333rem;
        
   }
   p{   
       font-family:PingFangSC-Regular;
        font-size:.346667rem;
        color:#cb9c57;
        letter-spacing:.0096rem;
        text-align:left;
        line-height :.533333rem;
        margin-top :.16rem;
   }
}
// 确认信息
.info-box{
    background-color :#fff;
    text-align:center;
    img{
        width :2.96rem;
        height :auto;
        margin .266667rem auto;
    }
    .goods-box{
        background:#fafafa;
        padding :.266667rem;
        overflow:hidden;
        .img-box{
            width :2.133333rem;
            height :2.133333rem;
            float:left;
            position:relative;
            img{
                width :100%;
                height:100%;
                margin :0;
            }
            img.label{
                width :1.093333rem;
                height :auto;
                position:absolute;
                left 0;
                top :0;
            }
        }
        dl{
            float:left;
            width :73%;
            margin-left :3.3%
            position :relative;
            height: 2.133333rem;
            dt{
                font-family:PingFangSC-Regular;
                font-size:.373333rem;
                color:#494949;
                letter-spacing:.008rem;
                line-height:.533333rem;
                text-align:left;
            }
            dd{
                position:absolute;
                bottom :0;   
                font-family:PingFangSC-Medium;
                font-size:13px;
                color:#cb9c57;
                letter-spacing:0;
                text-align:left;
                width :100%;
               
                span{
                    font-family:PingFangSC-Regular;
                    font-size:.346667rem;
                    color:#2d2d2d;
                    letter-spacing:0;
                    text-align:right;
                    position:absolute;
                    right :0;
                }             
            }
        }
    }
    .sold-box{
        margin-top :.133333rem;
    }
    //选择互换商品操作盒子区
    .handle-box{
        font-family:PingFangSC-Regular;
        font-size:.373333rem;
        color:#eb3148;
        line-height:.533333rem;
        text-align:left;
      
        padding: 0 .266667rem;
        .click-box{
            position: relative;
            height :1.066667rem;
            line-height :1.066667rem;
            span{
                 color:red;
            }
            img.arow{
                height :.32rem;
                width :auto;
                position :absolute;
                right :0;
                top: 50%;
                margin-top :-0.16rem;
            }
        }
        .selected{
            text-align :center;
            img{    
                height :.533333rem;
                width :auto;
            }
        }
      
    }
}
// 支付金额
.payMoney{
    background-color :#fff;
    margin-top :.266667rem;
    padding :.266667rem;
    p{
        text-align :center;
        img{
            width: 2.96rem;
            height: auto;
            margin-bottom :.266667rem;
        }
    }    
   .bottom{
       overflow :hidden;
       font-family:PingFangSC-Regular;
        font-size:.373333rem;
        color:#494949;
        line-height:20px;
       p{
           float:left;
       }
       p:last-child{
           float:right;
           font-family:PingFangSC-Medium;    
             color:#cb9c57;
       }
   }
}
// 选择支付方法
.choosePay{
    margin-top :.266667rem;
    margin-bottom :2.133333rem;
    background-color :#ffffff;
    .choosePay-txt{
        text-align :center;
        img{
            width: 3.76rem;
            height: auto;
            margin: 0.266667rem auto;
        }
    } 
    .relative{
        position:relative;
        .van-cell{
            padding-left :1.28rem!important; 
            font-family:PingFangSC-Regular;
            font-size:.346667rem!important;
            color:#494949;
            text-align:left;
        }
        .choosePay-icon{
            top: 50%;
            left: .4rem;
            margin-top: -0.34rem;
            width :.666667rem;
            height :.666667rem;
            position: absolute;
            z-index: 1;
        }
    }
    .borderbtm{
        border-bottom :.026667rem solid #f1f1f1;
    }   
            
}
// 底部操作按钮
.btn-box{
    position :fixed;
    padding-left :.4rem;
    left 0;
    bottom:0;
    opacity:0.9;
    background:#ffffff;
    box-shadow:0 0 8px 0 rgba(0,0,0,0.08);
    width:100%;
    height :1.306667rem;
    box-sizing :border-box;
    z-index: 999;
     text-align:center;
    .close{
        height :1.306667rem;
        line-height :1.306667rem;
        width :29%;
        font-family:PingFangSC-Regular;
        font-size:.4rem;
        color:#cb9c57;
         float:right;
    }
    .btn{
        background:#cb9c57;
        width:40%;;
        height :1.306667rem;
        line-height :1.306667rem;
        font-family:PingFangSC-Medium;
        font-size:.4rem;
        color:#ffffff;
        letter-spacing:.007733rem;
       
        float:right;
    }
}
.loading-box{
    width :50px;
    height :50px;
    border-radius :3px;
    background :rgba(0,0,0,.5);
    position :fixed;
    left :50%;
    top:50%;
    margin-left:-25px;
    margin-top :-25px;
    z-index :999999;
    text-align :center;
    vertical-align :middle;
    .van-loading{
       left :50%;
       top:50%;
       margin-left :-15px;
       margin-top :-15px;
    }
}
</style>


